#!/usr/bin/env python
# coding: utf-8

from PyQt5 import QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import  *
from data import *


class Staff(QWidget):

	staff_signal = pyqtSignal(list)

	def __init__(self):
		super(Staff, self).__init__()
		self.setFixedSize(200, 50)
		self.setWindowTitle("选择")
		self.set_ui()

	def set_ui(self):
		self.txt = QLineEdit()
		self.txt.setText('6')
		bnt = QPushButton("点击")
		bnt.clicked.connect(self.choose_staffs)

		layout = QHBoxLayout()
		layout.addWidget(self.txt)
		layout.addWidget(bnt)

		self.setLayout(layout)

	def choose_staffs(self):
		db = DB()
		db.cur.execute("select * from staff")
		staff_rslt_tmp = db.cur.fetchall()
		staff_rslt = [i[0] for i in staff_rslt_tmp]
		db.cur.execute("select num from numb")
		num_rslt = db.cur.fetchone()[0]
		len_given = int(self.txt.text())
		len_staff = len(staff_rslt)
		num = num_rslt + len_given
		if num  > len_staff:
			staff_rslt += staff_rslt
			rslt = staff_rslt[num_rslt: num]
			num_finnal = num % len_staff
		else:
			rslt = staff_rslt[num_rslt: num]
			num_finnal = num
		db.cur.execute("update numb set num = %d"%(num_finnal))
		db.con.commit()
		db.con.close()
		self.staff_signal.emit(rslt)
		self.close()
